package com.dfbz.springboot_project.controller;

import com.dfbz.springboot_project.entity.Result;
import com.dfbz.springboot_project.service.AdminInfoService;
import com.dfbz.springboot_project.service.AdminRoleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@RestController
@RequestMapping("adminInfo")
public class AdminInfoController {
    @Autowired
    AdminInfoService adminInfoService;
    @Autowired
    AdminRoleService adminRoleService;
    @RequestMapping("index")
    public ModelAndView index(){
        return new ModelAndView("/html/admin/admin_list.html");
    }
    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize){
        return new Result(true,"查询成功",adminInfoService.selectPage(pageNum,pageSize));
    }
    @RequestMapping("toUpdate")
    public ModelAndView toUpdate(){
        return new ModelAndView("/html/admin/admin_modi.html");
    }
    @RequestMapping(value = "selectOneByAid",method = RequestMethod.GET)
    public Result selectOneByAid(@Param("Aid") Integer Aid){
        return new Result(true,"查询成功",adminInfoService.selectOneByAid(Aid));
    }
    @RequestMapping("doUpdate")
    public Result doUpdate(@RequestBody Map<String,Object> params){
        adminInfoService.update(params);
        adminRoleService.updateSelective(params);
        return new Result(true,"更新成功",null);
    }
    @RequestMapping(value = "doDelete/{Aid}")
    public Result doDelete(@PathVariable Integer Aid){
        adminInfoService.deleteById(Aid);
        adminRoleService.deleteByAid(Aid);
        return new Result(true,"删除成功",null);
    }
    @RequestMapping("toInsert")
    public ModelAndView toInsert(){
        return new ModelAndView("/html/admin/admin_add.html");
    }
    @RequestMapping("doInsert")
    public Result doInsert(@RequestBody Map<String,Object> params){
        adminInfoService.InsertSelective(params);
        return new Result(true,"添加成功",null);
    }
}
